class Task {
    static of(x) {
        return new Task(() => x);
    }

    constructor(fn) {
        this.$value = fn;
    }

    map(fn) {
        return new Task(fn(this.$value));
    }

    inspect() {
        return `Task (${this.$value})`;
    }
}

// readFile :: String -> Task Error String
// const readFile = filename => new Task((reject, result) => {
//     fs.readFile(filename, (err, data) => (err ? reject(err) : result(data)));
// });
//
// readFile('metamorphosis').map(split('\n')).map(head);

let fs = require('fs');
let p = fileName => {
    return Task.of((succ, reject) => {
        fs.readFile(fileName, (err, data) => {
            if (err) {
                reject(err)
            } else {
                succ(data)
            }
        });
    });
};

p('./io.js').map(data => {
    console.dir(data)
});
